﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

using EShop.Model;
using EShop.Common;

namespace EShop.DAL
{
    public class MerchandiseUnitDAL:BaseDAL
    {
        /// <summary>
        /// 取商品单位所有数据
        /// </summary>
        /// <returns></returns>
        public List<MerchandiseUnitInfo> GetAllMerchandiseUnitList()
        {
            string strUSP = "USP_Merchandise_Unit_GetList";
            List<MerchandiseUnitInfo> aMerchandiseUnitInfoList = new List<MerchandiseUnitInfo>();

            try
            {
                SqlDataReader reader = (SqlDataReader) DbHelper.ExecuteReaderSQL(strUSP, CommandType.StoredProcedure);
                while (reader.Read())
                {
                    MerchandiseUnitInfo oinf=new MerchandiseUnitInfo();
                    oinf.UnitID = reader.GetInt32(0);
                    oinf.UnitName = reader[1].ToString();
                    aMerchandiseUnitInfoList.Add(oinf);
                }
                reader.Close();

                return aMerchandiseUnitInfoList;
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }

        public int MerchandiseUnitAppend(string strUnit)
        {
            string strUSP = "USP_MerchandiseUnit_Append";
            try
            {
                SqlParameter parameter = new SqlParameter("@UnitName", strUnit);
                return DbHelper.ExecuteNonQuerySQL(strUSP, CommandType.StoredProcedure, parameter);
            }
            catch (Exception ex)
            {
                log.Write((string.Format("USP: {0}, \r\n ex : {1}", strUSP, ex.Message)));
                throw;
            }
        }
    }
}
